//
//  LRXOrderMoreView.m
//  路人侠
//
//  Created by zhangxulong on 4/10/16.
//  Copyright © 2016 zhangxulong. All rights reserved.
//

#import "LRXOrderMoreView.h"
#import "LRXHelpMoreInfoCell.h"
@interface LRXOrderMoreView()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,weak) LRXHelpMeInfoModel * model;
@property (nonatomic,assign) CGFloat nowY;
@end
@implementation LRXOrderMoreView

- (void)layoutOrderMoreView:(LRXHelpMeInfoModel *)model
{
    self.nowY = 0;
    self.model = model;
    
    
    self.backgroundColor = [UIColor whiteColor];
    
    UILabel * headLabel = [[UILabel alloc]init];
    headLabel.frame = CGRectMake(0, 0, self.frame.size.width, 98 * hScale);
    headLabel.font = [UIFont systemFontOfSize:33 * hScale];
    headLabel.textColor = [UIColor whiteColor];
    headLabel.backgroundColor = mainColor;
    headLabel.textAlignment = NSTextAlignmentCenter;
    
    self.nowY = CGRectGetMaxY(headLabel.frame);
    

    //内容的设置
    //内容的设置
    if(model.statue == 0){
        [self layoutContentView];
        [self layoutFootView:@""];
        headLabel.text = @"支付超时";
    }
    else if (model.statue == 1) {
        [self layoutContentView];
        [self layoutFootView:@"付款"];
        headLabel.text = @"请支付该订单费用！";
    }
    else if (model.statue == 2) {
        [self layoutContentView];
        [self layoutFootView:@""];
        
        headLabel.text = @"订单还未被接单！";
    }
    else if (model.statue == 3) {
        
        [self layoutHelperInfo];
        
        [self layoutContentView];
        [self layoutFootView:@""];
        
        if (model.orderModel.status == 1) {
            
            headLabel.text = @"订单等待配送！";
        }
        else if(model.orderModel.status == 2)
        {
            headLabel.text = @"订单正在送货中！";
        }
        
    }
    else if(model.statue == 4)
    {
        if(model.orderModel.status == 3)
        {
            [self layoutHelperInfo];
            [self layoutContentView];
            [self layoutFootView:@"评价"];
            headLabel.text = @"配送完成";
        }
    }    [self addSubview:headLabel];
    
}

-(void)layoutHelperInfo
{
    UILabel * helperInfo = [[UILabel alloc]init];
    helperInfo.text = @"帮带人信息";
    helperInfo.textColor = [UIColor colorWithRed:255 green:156 blue:0];
    helperInfo.font = [UIFont systemFontOfSize:20 * hScale];
    helperInfo.frame = CGRectMake(31 * wScale, self.nowY + 20 * hScale, 0, 0);
    [helperInfo sizeToFit];
    [self addSubview:helperInfo];
    
    self.nowY = CGRectGetMaxY(helperInfo.frame);
    
    
    if (self.model.userInfo) {
        UIImageView * userIcon = [[UIImageView alloc]init];
        if (![self.model.orderModel.helperProfile_url isEqual:[NSNull null]]) {
            self.model.orderModel.helperProfile_url = @"";
        }
        [userIcon sd_setImageWithURL:[NSURL URLWithString:[routeImageUrl stringByAppendingString:self.model.orderModel.helperProfile_url]] placeholderImage:[UIImage imageNamed:@"de"]];
        userIcon.frame = CGRectMake(34 * wScale, self.nowY + 23 * hScale, 81 * hScale, 81 * hScale);
        userIcon.layer.cornerRadius = userIcon.frame.size.height * 0.5;
        userIcon.layer.masksToBounds = YES;
        
        
        UILabel * userName = [[UILabel alloc]init];
        userName.text = self.model.userInfo.userName;
        userName.font = [UIFont systemFontOfSize:20 * hScale];
        userName.frame = CGRectMake(CGRectGetMaxX(userIcon.frame) + 36 * wScale, self.nowY + 29 * hScale, 0, 0);
        [userName sizeToFit];
        
        UILabel * speeReLabel = [[UILabel alloc]init];
        speeReLabel.text = @"速度";
        speeReLabel.font = [UIFont systemFontOfSize:24 * hScale];
        speeReLabel.frame = CGRectMake(CGRectGetMaxX(userIcon.frame) + 36 * hScale, CGRectGetMaxY(userName.frame) + 30 * hScale, 0, 0);
        [speeReLabel sizeToFit];
        
        UILabel * speeLabel = [[UILabel alloc]init];
        speeLabel.text = self.model.orderModel.helperSpeed_rank;
        speeLabel.font = speeReLabel.font;
        speeLabel.frame = CGRectMake(CGRectGetMaxX(speeReLabel.frame) + 20 * wScale, speeReLabel.frame.origin.y, 0, 0);
        [speeLabel sizeToFit];
        
        
        
        UILabel * serReLabel = [[UILabel alloc]init];
        serReLabel.text = @"服务";
        serReLabel.font = [UIFont systemFontOfSize:24 * hScale];
        serReLabel.frame = CGRectMake(CGRectGetMaxX(userIcon.frame) + 226 * hScale, CGRectGetMaxY(userName.frame) + 30 * hScale, 0, 0);
        [serReLabel sizeToFit];

        UILabel * serLabel = [[UILabel alloc]init];
        serLabel.text = self.model.orderModel.helperManner_rank;
        serLabel.font = speeReLabel.font;
        serLabel.frame = CGRectMake(CGRectGetMaxX(serReLabel.frame) + 20 * wScale, serReLabel.frame.origin.y, 0, 0);
        [serLabel sizeToFit];
        
        [self addSubview:userIcon];
        [self addSubview:userName];
        [self addSubview:speeLabel];
        [self addSubview:speeReLabel];
        [self addSubview:serLabel];
        [self addSubview:serReLabel];
        
        self.nowY = CGRectGetMaxY(speeReLabel.frame) + 29 * hScale;
        
        UIView * lineView =[[UIView alloc]init];
        lineView.backgroundColor = [UIColor colorWithRed:238 green:238 blue:238];
        lineView.frame = CGRectMake(0, self.nowY, self.frame.size.width, 2 * hScale);
        [self addSubview:lineView];

    }
}

//设置内容
- (void)layoutContentView
{
    UITableView * tableView = [[UITableView alloc]init];
    tableView.frame = CGRectMake(90 * wScale, self.nowY + 28 * hScale, self.frame.size.width - 180 * wScale, 88 * self.model.thingArray.count * hScale);
    tableView.rowHeight = 88 * hScale;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView.delegate = self;
    tableView.dataSource = self;
    
    self.nowY = CGRectGetMaxY(tableView.frame);
    [self addSubview:tableView];
    
}
- (void)layoutFootView:(NSString *)footTitle
{
    if (footTitle.length > 0 ) {
        
        self.nowY += 70 * hScale;
        UIView * lineView =[[UIView alloc]init];
        lineView.backgroundColor = mainColor;
        lineView.frame = CGRectMake(0, self.nowY, self.frame.size.width, 2 * hScale);
        
        [self addSubview:lineView];
        
        
        UIButton * statusBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [statusBtn setTitle:footTitle forState:UIControlStateNormal];
        statusBtn.titleLabel.font = [UIFont systemFontOfSize:34 * hScale];
        statusBtn.frame = CGRectMake(354 * wScale, self.nowY + 41 * hScale, 153 * wScale, 32 * hScale);
        [self addSubview:statusBtn];
        
        
    }
    self.nowY += 103 * hScale;
    self.maxHeight = self.nowY;

    
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * LRXORDERMOREVIEWCELL = @"LRXORDERMOREVIEWCELL";
    LRXHelpMoreInfoCell * cell = [tableView dequeueReusableCellWithIdentifier:LRXORDERMOREVIEWCELL];
    if (cell == nil) {
        cell = [[LRXHelpMoreInfoCell alloc]init];
    }
    
    [cell layoutHelpMoreCell:self.model.thingArray[indexPath.row]];
    
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.model.thingArray.count;
}
@end
